import emitter from "../utils/eventbus";
import * as d3 from "d3";
import d3DrawStore from "../store/modules/d3Draw";

/**
 * 
 * @param $ 
 * @param height 
 * @param width 
 * @param d3CanvasRef 
 * @returns 
 */
//初始化裸眼井（增）
export function initOpenHole($: any, d3CanvasRef: any, width: number, heightStart: number, heightEnd: number ) {
    let id: string = $.attr("id");
    const d3Canvas = d3CanvasRef;//画布信息
    const widthCenter = d3Canvas.offsetWidth / 2 //中心线
    const yScale = d3DrawStore().scale
    const start = yScale(heightStart)
    const end = yScale(heightEnd)
    //裸眼井
    const openHole = { left: undefined, right: undefined}
    openHole.left = $.append("line")
        .attr("x1", widthCenter - width / 2)
        .attr("y1", start)
        .attr("x2", widthCenter - width / 2)
        .attr("y2", end)
        .attr("stroke-width", 2)
        .attr("stroke", "brown");
    openHole.right = $.append("line")
        .attr("x1", widthCenter + width / 2)
        .attr("y1", start)
        .attr("x2", widthCenter + width / 2)
        .attr("y2", end)
        .attr("stroke-width", 2)
        .attr("stroke", "brown");
    // const waveLeft = d3
    //     .line()
    //     .curve(d3.curveBasis)
    //     .y((d, i) => yStart + (yEnd - yStart) * i / (height - 1))
    //     .x((d) => (Math.sin(d) * 2 + widthCenter - (width / 2)));
    // const waveRight = d3
    //     .line()
    //     .curve(d3.curveBasis)
    //     .y((d, i) => i * (yEnd - yStart) / (height - 1) + yStart)
    //     .x((d) => Math.sin(d) * 2 + widthCenter + (width / 2));
    // const lineData = Array.from(
    //     { length: height },
    //     (_, i) => (Math.PI / 2) * i
    // );
    // openHole.left = $.append("path")
    //     .attr("d", waveLeft(lineData))
    //     .attr("fill", "none")
    //     .attr("stroke", "black")
    //     .attr("stroke-width", 2)
    // openHole.right = $.append("path")
    //     .attr("d", waveRight(lineData))
    //     .attr("fill", "none")
    //     .attr("stroke", "black")
    //     .attr("stroke-width", 2)
    // openHole.bottom = $.append("line")
    //     .attr("x1", widthCenter - (width / 2))
    //     .attr("y1", height - 5)
    //     .attr("x2", widthCenter + (width / 2))
    //     .attr("y2", height - 5)
    //     .attr("stroke", "black");
    emitter.on(id, (transform: any) => {
        openHole.left.attr("transform", transform);
        openHole.right.attr("transform", transform);
        // openHole.bottom.attr("transform", transform);
    });
    return openHole
}

//删除裸眼井（删）
export function deleteOpenHole($: any) {

}

//修改裸眼井（改）
export function editOpenHole($: any) {

}

//查询裸眼井（查）
export function findOpenHole($: any) {

}
